$(function () {

    var now = new Date();
    $("#chuKuTime").val = now.getFullYear() + "-"
        + (now.getMonth() + 1) + "-" + now.getDate();


    $("#i1").change(function () {
        var shuRu = $("#i1").val();
        $.ajax({
            type: "get",
            url: "http://localhost:10000/chuku/huoZhu/" + shuRu,
            success: function (data) {
                console.log("显示信息:" + JSON.stringify(data))
                $("#t1").html("");
                if (shuRu != "") {
                    $("#d1").attr("hidden", false);
                    for (var i = 0; i < data.length; i++) {
                        $("#t1").append("<tr onclick='xiuGai(this)' onmouseover='changeDivBC(this)' onmouseout='changeDivBC1(this)'><td style='width: 100px'>" + data[i].custID + "</td><td style='width: 100px'>" + data[i].custName + "</td><td style='width: 100px'>" + data[i].custMobile + "</td><td style='width: 100px'>" + data[i].custTel + "</td></tr>")
                    }
                } else {
                    $("#d1").attr("hidden", true);
                }
            }
        })
    })

    // $("#t1").on("click", "tr", function () {//给asd的tr新增点击事件
    //     //首先用 alert("点击事件是否触发");
    //     //alert("点击事件是否触发");
    //     location.href = "http://localhost:10000/chuku/fuZhi/";
    // })

    $("#billFeeStore").change(function () {
        var billFeeStore = document.getElementById("billFeeStore").value
        var billFeeOther =document.getElementById("billFeeOther").value
        if ((billFeeStore!=null||billFeeStore!="")&&(billFeeOther!=null||billFeeOther!="")){
            $("#billFeeTotal").val(Number.parseInt(billFeeStore)+Number.parseInt(billFeeOther))
        }else {
            window.alert("库存费用和其他费用不能为空")
        }
    })
    $("#billFeeOther").change(function () {
        var billFeeStore = document.getElementById("billFeeStore").value
        var billFeeOther =document.getElementById("billFeeOther").value
        if ((billFeeStore!=null||billFeeStore!="")&&(billFeeOther!=null||billFeeOther!="")){
            $("#billFeeTotal").val(Number.parseInt(billFeeStore)+Number.parseInt(billFeeOther))
        }else {
            window.alert("库存费用和其他费用不能为空")
        }

    })

})

function xiuGai(div1) {

    //获取得到需要的值
    var want = div1.cells[2].innerHTML + ":" + div1.cells[1].innerHTML;
    //custId
    var custID = div1.cells[0].innerHTML

    //2 输入框的内容是你点击的div的内容
    $("#i1").val(want);
    //隐藏input塞入custId
    $("#i2").val(custID);

    //1 让下方div内容清空
    $("#d1").html("");

    //ajax发送custID给后台获取出库货物明细
    var custID = div1.cells[0].innerHTML
    $.ajax({
        type: "get",
        url: "http://localhost:10000/chuku/selChuKu/" + custID,
        success: function (data) {
            // $("#t2").html("");
            var toWei;
            for (var i = 0; i < data.length; i++) {
                //出库重量(出库重量==规格*提货数量)
                var weight=(data[i].detailsGoodsNum)*(data[i].detailsGoodsSpec);
                $("#tbody1").append("" +
                    "<tr>" +
                    "<td>"+data[i].trayID+"</td>" +
                    "<td>"+data[i].detailsGoodsName+"</td>" +
                    "<td>"+data[i].detailsGoodsSpec+"</td>" +
                    "<td>"+data[i].currentGoodsNum+"</td>" +
                    "<td>"+data[i].detailsGoodsNum+"</td>" +
                    "<td>"+weight+"</td>" +
                    "</tr>");

                console.log("该集合为:" + JSON.stringify(data[i]))
                //托盘编号
                $("#trayID").val(data[i].trayID);
                //货物名称
                $("#Name").val(data[i].detailsGoodsName);
                //规格(公斤/件)
                $("#Spec").val(data[i].detailsGoodsSpec);
                //现存件数
                $("#currentGoodsNum").val(data[i].currentGoodsNum);
                //提货件数
                $("#detailsGoodsNum").val(data[i].detailsGoodsNum);
                //出库重量(出库重量==规格*提货数量)
                $("#weight").val(weight);
                toWei= toWei+weight
            }
            //托盘个数
            $("#fbillNum").append(data.length)
            $("#billNum").val(data.length)
            //总重量(公斤)
            $("#fToWei").append(weight)
            $("#toWei").val(toWei)

        }
    })

}

function changeDivBC(div2) {
    div2.style.backgroundColor = "gray";
}

function changeDivBC1(div2) {
    div2.style.backgroundColor = "pink";
}

//时间
/*function datetime() {
    var now = new Date();
    $("#chuKuTime").val = now.getFullYear() + "-"
        + (now.getMonth() + 1) + "-" + now.getDate();
}
window.setInterval("datetime()");*/

